package com.xzjt.web.controller.system;

import java.util.Arrays;
import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xzjt.common.annotation.Log;
import com.xzjt.common.core.controller.BaseController;
import com.xzjt.common.core.domain.R;
import com.xzjt.common.enums.BusinessType;
import com.xzjt.system.domain.EquipInfo;
import com.xzjt.system.service.IEquipInfoService;
import com.xzjt.common.utils.poi.ExcelUtil;
import com.xzjt.common.core.page.TableDataInfo;

/**
 * 设备信息Controller
 * @author xzjt
 * @date 2021-09-01
 */
@RestController
@RequestMapping("/system/equip")
public class EquipInfoController extends BaseController {
    @Autowired
    private IEquipInfoService equipInfoService;

    /**
     * 查询设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:equip:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipInfo equipInfo) {
        startPage();
        List<EquipInfo> list = equipInfoService.selectEquipInfoList(equipInfo);
        return getDataTable(list);
    }

    /**
     * 导出设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:equip:export')")
    @Log(title = "设备信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(EquipInfo equipInfo) {
        List<EquipInfo> list = equipInfoService.selectEquipInfoList(equipInfo);
        ExcelUtil<EquipInfo> util = new ExcelUtil<EquipInfo>(EquipInfo. class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取设备信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:equip:query')")
    @GetMapping(value = "/{equipid}")
    public R getInfo(@PathVariable("equipid") Long equipid) {
        return R.success(equipInfoService.getById(equipid));
    }

    /**
     * 新增设备信息
     */
    @PreAuthorize("@ss.hasPermi('system:equip:add')")
    @Log(title = "设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody EquipInfo equipInfo) {
        return result(equipInfoService.save(equipInfo));
    }

    /**
     * 修改设备信息
     */
    @PreAuthorize("@ss.hasPermi('system:equip:edit')")
    @Log(title = "设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody EquipInfo equipInfo) {
        return result(equipInfoService.updateById(equipInfo));
    }

    /**
     * 删除设备信息
     */
    @PreAuthorize("@ss.hasPermi('system:equip:remove')")
    @Log(title = "设备信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{equipids}")
    public R remove(@PathVariable Long[] equipids) {
        return result(equipInfoService.removeByIds(Arrays.asList(equipids)));
    }
}
